package truncateSentence;

public class Solution {
    public String truncateSentence(String s, int k) {
        int index = 0;
        for (index = 0; index <s.length()&&k>0 ;index++) {
            if(s.charAt(index) == ' '){
                k--;
            }
        }
        return s.substring(0,index == s.length()?index:index-1);
    }
}
